package com.testfileupload.uploadimg.design.intermediary.zhongjie;

public class Mediator extends AbstractMediator {
    @Override
    public void execute(String str, Object... obj) {
        if ("purcher.buy".equals(str)) {
            this.purcchaseBuy((Integer) obj[0]);
        } else if ("sale.sell".equals(str)) {
            this.saleSell((Integer) obj[0]);
        } else if ("sale.offsell".equals(str)) {
            this.salOffSell();
        } else if ("stock.clear".equals(str)) {
            this.stockClear();
        }
    }

    private void stockClear() {
        super.sale.offSale();
        super.purcchase.refuseBuyIBM();
    }

    private void salOffSell() {
        System.out.println("折价销售" + stock.getComputerNum() + "台");
    }

    private void saleSell(Integer integer) {
        if (super.stock.getComputerNum() < integer) {
            super.purcchase.buyIBMComputer(integer);
        }
        super.stock.decrease(integer);
    }

    private void purcchaseBuy(Integer num) {
        int saleStatus = super.sale.getSaleStatus();
        if (saleStatus > 80) {//销售数量好
            System.out.println("采购数量为" + num);
            super.stock.increase(num);
        } else {//销售数量不好
            int num2 = num / 2;
            System.out.println("采购数量折半为" + num2);
            super.stock.increase(num2);
        }
    }
}
